﻿using System;
using System.Collections.Generic;
using System.Text;
using Kugar.Core.ExtMethod;
using Kugar.Core.Web;
using Kugar.UI.Web.AdminLTE.Enums;
using Kugar.UI.Web.AdminLTE.Helpers;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Kugar.UI.Web.AdminLTE.PageControls.PageCommon
{
    /// <summary>
    /// 输出一个Callout控件,参考AdminLte的UI/general中的Callout样式
    /// </summary>
    public class PageCommon_Callout:ControlBase
    {
        private ColorPaletteEnum _color = ColorPaletteEnum.info;
        private string _title = "";
        private string _text = "";

        public PageCommon_Callout(ViewContext viewContext) : base(viewContext)
        {
            this.Css("callout webui-ctrl-callout");
        }

        /// <summary>
        /// Callout控件的颜色
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public PageCommon_Callout Color(ColorPaletteEnum color)
        {
            _color = color;

            return this;
        }

        /// <summary>
        /// 标题
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public PageCommon_Callout Title(string title)
        {
            _title = title;

            return this;
        }

        /// <summary>
        /// 标题
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public PageCommon_Callout Title(Func<object, HelperResult> title)
        {
            _title = title(this).ToHtmlString().ToStringEx();

            return this;
        }

        /// <summary>
        /// 提示的详细文本
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public PageCommon_Callout Text(string text)
        {
            _text = text;

            return this;
        }

        /// <summary>
        /// 提示的详细文本
        /// </summary>
        /// <param name="text">razor的html模板</param>
        /// <returns></returns>
        public PageCommon_Callout Text(Func<object,HelperResult> text)
        {
            _text = text(this).ToHtmlString().ToStringEx();

            return this;
        }

        public override HtmlString Render()
        {
            /*
             <div class="callout callout-warning">
                <h4>I am a warning callout!</h4>

                <p>This is a yellow callout.</p>
              </div>
             */

            this.Css("callout-" + _color);

            ViewContext.Writer.WriteLine($"<div {Attributes}>");

            ViewContext.Writer.WriteLine($"<h4>{_title}</h4>");
            ViewContext.Writer.WriteLine($"<p>{_text}</p>");

            ViewContext.Writer.WriteLine("</div>");

            return HtmlString.Empty;
        }
    }
}
